﻿<%@ WebHandler Language="C#" Class="SYS_Category_add" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;

public class SYS_Category_add : IHttpHandler,IRequiresSessionState {
    sqlhelp sql = new sqlhelp();
    result result = new result();
    string str = "";
    public void ProcessRequest (HttpContext context) {            
            try
            {
                if (context.Session["comid"] == null)
                {
                    result.code = "-1";
                    result.msg = "用户未登录";
                    unit.send(context, result);
                    return;
                }

                string Id = Guid.NewGuid().ToString();
                string StoreId = context.Session["comid"].ToString();
                string Name = "";
                string CreateTime = DateTime.Now.ToString();
                string Enable = "1";
                
                if (context.Request["Name"] == null)
                {
                    result.code = "0";
                    result.msg = "未传递商品类别参数";
                    unit.send(context, result);
                    return;
                }
                else {
                    Name = context.Request["Name"].ToString();
                }

                str = "insert into SYS_Category(Id,StoreId,Name,CreateTime,Enable) values('" + Id + "','" + StoreId + "','" + Name + "','" + CreateTime + "'," + Enable + ")";
                if (sql.ExecuteNonQuery(str) > 0)
                {
                    result.code = "1";
                    result.msg = "";
                }
                else
                {
                    result.code = "0";
                    result.msg = "添加失败";
                }

            }
            catch (Exception e1)
            {
                result.code = "0";
                result.msg = e1.Message;
            }
        
            
        unit.send(context, result);
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
